var KeyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function URLEncode(str)
{
    str=escape(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
}

function EncodeBase64(input)
{
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + KeyStr.charAt(enc1) + KeyStr.charAt(enc2) + 
         KeyStr.charAt(enc3) + KeyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

var WJSLoader =
{
	settings :
	{
		compressor : '/Themes/Default/JS/loader.php',
		files      : new Array()
	},

	Include : function(s)
	{
	    /* Apply Loader Settings */
		for (n in s)
			this.settings[n] = s[n];
			
		/* Generate Query String */
		var qry_str = '';	
			
		for (file in this.settings.files)
			qry_str += this.settings.files[file] + '|';		
				
		qry_str = this.settings.compressor + "?i=" + URLEncode(EncodeBase64(qry_str));
		
		/* Load the GZip encoded JS into the current page */		
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			var x;
			
			try
			{
				x = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (ex)
			{
				x = new ActiveXObject("Msxml2.XMLHTTP");
			}

			x.open("GET", qry_str, false);
			x.send(null);

			this.JSData = x.responseText;

			document.write('<script type="text/javascript">eval(WJSLoader.JSData);</script>');
		}
		else
			document.write('<script type="text/javascript" src="' + qry_str + '"></script>');		
	}
}
